package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.ParticipantOrderBean;
import com.jucai.pppeiyouclient.comm.CommonRequestNetData;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.view.dialog.RefuseReasonDialog;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Kuky on 2017-05-05.
 */

public class NegParAgreedAdapter extends CommonRecyclerViewAdapter<ParticipantOrderBean> {
    private static final String TAG = "NegParAgreedAdapter : ";

    public NegParAgreedAdapter(Context context, List<ParticipantOrderBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(final CommonHolder holder, final ParticipantOrderBean participantOrderBean) {

        holder.setImage(R.id.part_img, participantOrderBean.getMember_avatar(), 80, 80);
        holder.setText(R.id.part_phone, participantOrderBean.getMember_phone());
        holder.setVisible(R.id.agreed);

        if (TextUtils.equals(participantOrderBean.getAct_order_sign_in(),"0")) {
            holder.setOnclickListener(R.id.not_sign, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    HashMap<String, String> singParam = new HashMap<>();
                    singParam.put("service", "Conductor_Activity.SignInMember");
                    singParam.put("act_order_id", participantOrderBean.getAct_order_id());
                    CommonRequestNetData.getJsonString(mContext, false, singParam, new CommonRequestNetData.JsonStringCallBack() {
                        @Override
                        public void parseJsonString(String str) {
                            LogUtils.e(TAG + str);
                        }
                    });

                    holder.setBackground(R.id.not_sign, R.drawable.shape_round_corner_orange_4dp);
                    holder.setText(R.id.not_sign, "已签到");
                    holder.setInvisible(R.id.delete);
                }
            });

            holder.setOnclickListener(R.id.delete, new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    final RefuseReasonDialog reasonDialog = new RefuseReasonDialog(mContext);
                    reasonDialog.negOrAgree(false);
                    reasonDialog.setOnclickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            LogUtils.e(TAG + " : dialog click");
                            String reason = reasonDialog.getReason();

                            HashMap<String, String> param = new HashMap<>();
                            param.put("service", "Conductor_Activity.delapplyuser");
                            param.put("id", participantOrderBean.getAct_order_id());
                            param.put("remark", reason);
                            LogUtils.e(TAG + "param = " + param.toString());
                            CommonRequestNetData.getJsonStringData(mContext, param, true, new CommonRequestNetData.JsonStringCallBack() {
                                @Override
                                public void parseJsonString(String str) {
                                    LogUtils.e(TAG + "str = " + str);
                                    removeData(participantOrderBean);
                                    notifyItemRemoved(getRealPos(holder));
                                }
                            });
                        }
                    });
                    reasonDialog.show();
                }
            });
        } else if (TextUtils.equals(participantOrderBean.getAct_order_sign_in(),"1")) {
            holder.setBackground(R.id.not_sign, R.drawable.shape_round_corner_orange_4dp);
            holder.setText(R.id.not_sign, "已签到");
            holder.setInvisible(R.id.delete);
        }
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_participant_layout;
    }
}
